package baizhi.action;

import baizhi.entity.Classes;
import baizhi.entity.Student;
import baizhi.service.ClassesService;
import baizhi.service.Impl.ClassesServiceImpl;
import baizhi.service.Impl.StudentServiceImpl;
import baizhi.service.StudentService;

import java.util.List;

public class StudentAction {
    private Integer pageNum;
    private Integer pageSize;
    private Integer totalPages;
    private List<Student> students;
    private List<Classes> list;
    private Student student;
    private Integer[] ids;
    private String name;
    private Integer age1;
    private Integer age2;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge1() {
        return age1;
    }

    public void setAge1(Integer age1) {
        this.age1 = age1;
    }

    public Integer getAge2() {
        return age2;
    }

    public void setAge2(Integer age2) {
        this.age2 = age2;
    }

    public List<Classes> getList() {
        return list;
    }

    public void setList(List<Classes> list) {
        this.list = list;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Integer[] getIds() {
        return ids;
    }

    public void setIds(Integer[] ids) {
        this.ids = ids;
    }
    public String getClasses(){
        ClassesService cs = new ClassesServiceImpl();
        list = cs.selectAll();
        return "add";
    }
    public String add(){
        StudentService service = new StudentServiceImpl();
        service.add(student);
        return "success";
    }
    public String removeOne(){
        StudentService service = new StudentServiceImpl();
        service.removeOne(student.getStudentId());
        return "success";
    }
    public  String removeAny(){
        System.out.println(ids);
        StudentService service = new StudentServiceImpl();
        service.removeAny(ids);
        return "success";
    }
    public String getOne(){
        StudentService service = new StudentServiceImpl();
        student = service.getOne(student.getStudentId());
        ClassesService cs = new ClassesServiceImpl();
        list = cs.selectAll();
        return "update";
    }
    public String update(){
        System.out.println(student);
        StudentService service = new StudentServiceImpl();
        service.updateOne(student);
        return "success";
    }
    public String showAll(){
        System.out.println(22);
        if(pageNum==null) pageNum=1;
        if(pageSize==null) pageSize=2;
        StudentService service = new StudentServiceImpl();
        students = service.selectPage(pageNum, pageSize, name, age1, age2);
        Integer total = service.total(name, age1, age2);
        totalPages = total%pageSize==0 ? total/pageSize:total/pageSize+1;
        return "showlist";
    }
}
